<script>
  // requestAnimationFrame模拟setTimeout
  function _setTimeout(callback, timeout) {
    let raf = window.requestAnimationFrame(step);
    const start = Date.now();
    function step(timestamp) {
      if ((Date.now() - start) > timeout) {
        callback();
        window.cancelAnimationFrame(raf);
      } else {
        raf = window.requestAnimationFrame(step);
      }
    }
  }

  // requestAnimationFrame模拟setInterval
  function _setInterval(callback, timeout) {
    window.requestAnimationFrame(step);
    let start = Date.now();
    function step(timestamp) {
      const current = Date.now();
      if ((current - start) / timeout > 1) {
        callback();
        start = current;
      }
      window.requestAnimationFrame(step);
    }
  }
</script>